﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace DiscMaster.Web.Security
{
    public class MembershipProvider : SqlMembershipProvider
    {
        DiscMaster.Web.Models.DiscMasterRepository repository = new DiscMaster.Web.Models.DiscMasterRepository();
        public bool SetMinimumDetailsForNewUser(string username, DateTime dateofbirth, byte gender)
        {
            var player = repository.GetPlayerByName(username);
            if (player != null)
            {
                if (player.PlayerDetail==null)
                {
                    player.PlayerDetail = new DiscMaster.Web.Models.PlayerDetail() { playerid = player.UserId };
                };
                player.PlayerDetail.dateofbirth = dateofbirth;
                player.PlayerDetail.gender = gender;

                repository.Save();

                return true;
            }
            else
            {
                return false;
            }
        }
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            var player = repository.GetPlayerByName(username);
            if (player!=null)
            {
                repository.DeletePlayer(player);
                repository.Save();
            }
            return base.DeleteUser(username, deleteAllRelatedData);
        }
    }
}
